package com.joplus.housekeeper.ui.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ListView;

import com.joplus.housekeeper.R;
import com.joplus.housekeeper.adapter.ChatCalendarAdapter;
import com.joplus.housekeeper.base.BaseActivity;
import com.joplus.housekeeper.bean.ChatMessageBean;
import com.joplus.housekeeper.network.RequestHelper;
import com.joplus.housekeeper.network.RetrofitHelper;
import com.joplus.housekeeper.network.TextCallback;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by zisheng on 2017/9/19.
 */

public class ChatCalendarActivity extends BaseActivity {

    private ListView lv;
    private String accountId;

    @Override
    protected int initLayout() {
        return R.layout.activity_hotel_calendar;
    }

    @Override
    protected void initViews(Bundle savedInstanceState) {
        lv = (ListView) findViewById(R.id.lv);
        accountId = getIntent().getStringExtra("accountId");

    }

    Map<String, List<Integer>> timeMap = new HashMap();

    @Override
    protected void initDatas() {
        toolBar.setTittle("聊天记录(日期查找)");

        RequestHelper.getInstance().chatTime(context, accountId, new TextCallback() {
            @Override
            public void onFailure(String responseString) {

            }

            @Override
            public void onSuccess(Object responseString) {
                ChatMessageBean chatMessage = (ChatMessageBean) responseString;
                if (chatMessage.getCode().equals("2000")) {
                    String dataBean = chatMessage.getData().get(0);
                    for (int i = 0; i < chatMessage.getData().size(); i++) {
                            String substring = chatMessage.getData().get(i).substring(0, 7);
                            String substring2 = chatMessage.getData().get(i).substring(8);
                            if (timeMap.containsKey(substring)) {
                                List<Integer> strings = timeMap.get(substring);
                                strings.add(Integer.valueOf(substring2));
                            } else {
                                List<Integer> objects = new ArrayList<>();
                                objects.add(Integer.valueOf(substring2));
                                timeMap.put(substring, objects);
                            }
                    }

                    lv.setAdapter(new ChatCalendarAdapter(context, dataBean, timeMap, accountId));
                }
            }
        });
    }

    @Override
    protected void initEvents() {

    }

    @Override
    protected boolean isSlideFinishActivity() {
        return false;
    }

    @Override
    protected int setTranslucentStatusColor() {
        return 0;
    }
}
